package com.ssl.springframework.beans.factory.support;

import com.ssl.springframework.beans.factory.BeanFactory;
import com.ssl.springframework.beans.factory.config.BeanDefinition;

/**
 * 描述：负责获取Bean
 *
 * @author ssl
 * @create 2021/6/11 0011.
 */
public abstract class AbstractBeanFactory extends DefaultSignletonBeanRegistry implements BeanFactory {

    @Override
    public Object getBean(String beanName) {
        return doGetBean(beanName);
    }

    @Override
    public Object getBean(String beanName, Object... args) {
        return doGetBean(beanName, args);
    }

    protected Object doGetBean(final String beanName, final Object... args) {
        Object bean = getSignleton(beanName);
        if (null != bean) {
            return bean;
        }
        // 创建bean
        BeanDefinition beanDefinition = getBeanDefinition(beanName);
        return createBean(beanName, beanDefinition,args);
    }

    protected abstract BeanDefinition getBeanDefinition(String beanName);


    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition,Object... args);

}
